﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InfoSoftGlobal;

namespace McDonalds_v1._0
{
    public class YearMonth
    {
        public int jaar { get; set; }
    }

    public partial class Omzet : System.Web.UI.Page
    {
        McDonaldsDataContext db = new McDonaldsDataContext();
        List<YearMonth> YearMonth = new List<YearMonth>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                var jaartal = Jaar.SelectedValue;
                string maand = Maand.SelectedValue;
                string maandnaam = Maand.SelectedItem.Text;
                text_overzicht.Text = "Overzicht van " +jaartal;
                if(maandnaam != "Kies een maand") {
                    text_overzicht.Text += " " + maandnaam; 
                }
                text_overzicht.Visible = true;

                string url = "http://localhost:54805/WebService1.asmx/omzetXML?year=" + jaartal + "&month="+maand;
                Literal1.Text = FusionCharts.RenderChart("Charts/Column3D.swf", url, "", "myFirst", "400", "300", false, true);

            }


            if (!IsPostBack)
            {
                var jaartallen = from order in db.ORDERs
                                 group order by new { order.DATUM.Year } into orderjaren
                                 select new YearMonth { jaar = orderjaren.Key.Year };

                foreach (YearMonth jaarmaand in jaartallen)
                {
                    ListItem li = new ListItem();
                    li.Text = jaarmaand.jaar.ToString();
                    li.Value = jaarmaand.jaar.ToString();
                    Jaar.Items.Add(li);
                }
            }
            

        }
    }
}